package com.lucene;

import com.alibaba.fastjson.JSONObject;
import com.db.utils.DBUtils;
import com.utils.DBSql;

import java.util.List;
import java.util.Map;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/8/1 0:15
 * @since JDK 1.8
 */
public class LuceneScript {

    public static void main(String[] args) throws Exception {
     //   create();
        mapListSearch("json的工具类使用").forEach(k->{
           String str= JSONObject.toJSONString(k);
            System.out.println(str);
        });
    }

    public static List<Map<String, Object>> mapListSearch(String title) throws Exception{
      return   LuceneUtils.searchByKeyWord("mnote","title",title,1000);
    }

    public static void create() throws Exception{
        DBUtils.initDBUtils("jdbc:mysql://localhost:3306/spring-demo?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull"
                ,"com.mysql.cj.jdbc.Driver","admin","root"
                );
        List<Map<String, Object>> mapList=DBUtils.selectMapList("SELECT * FROM `spring-demo`.`m_note` LIMIT 0,1000");
        mapList.forEach((k)->{
            System.out.println(JSONObject.toJSON(k));
        });
        LuceneUtils.addListDocumentByIndexName("mnote",mapList);
    }

}
